import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";

// console.log("process.env: ", process.env);
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), "");

  return {
    plugins: [vue()],
    // base: mode == "production" ? "/img2video/" : "./",
    // publicDir: "/img2video/",
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
    server: {
      // host: '0.0.0.0', //只能使用localhost
      //处理ffmpeg的SharedArrayBuffer is not defined
      headers: {
        "Cross-Origin-Embedder-Policy": "require-corp",
        "Cross-Origin-Opener-Policy": "same-origin",
      },

      proxy: {
        // with options
        "/images": {
          target: "http://ecowitt.oss-cn-shanghai.aliyuncs.com/images",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/images/, ""),
        },
      },
    },
  };
});
